package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.gdms.model.Application;
import com.zr.gdms.model.User;
import com.zr.gdms.service.CourseService;
import com.zr.gdms.serviceimpl.CourseServiceImpl;

import net.sf.json.JSONArray;

public class showApplicationControllerZYH extends HttpServlet{
	
	CourseService cs = new CourseServiceImpl();
	
	@Override
	public void init() throws ServletException {
		System.out.println("34535");
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		HttpSession  session =req.getSession();
		PrintWriter  pw = resp.getWriter();
		User u = (User) session.getAttribute("user");
		System.out.println(u.getUid());
		List<Application> a = cs.findCourseFromApByUid(u.getUid());
		JSONArray  j = JSONArray.fromObject(a);
		pw.write(j.toString());
		
	}
}
